package com.cmccgz.baselibrary.utils;

import android.content.Context;
import android.widget.Toast;

/**
 * 
 * @ClassName: ToastUtils
 * @Description: ToastUtils
 * @author Mr.sun
 * @date 2015年12月15日 下午8:18:35
 *
 */
public class ToastUtils {

	private static Toast toast = null;

	private static void show(Context context, CharSequence text, int duration) {
		if (toast == null) {
			toast = Toast.makeText(context, text, duration);
		} else {
			toast.setText(text);
			toast.setDuration(duration);
		}
		toast.show();
	}

	public static void toastShort(Context context, String text) {
		show(context, text, Toast.LENGTH_SHORT);
	}

	public static void toastLong(Context context, String text) {
		show(context, text, Toast.LENGTH_LONG);
	}

	public static void show(Context context, int resId) {
		show(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
	}

	public static void show(Context context, int resId, int duration) {
		show(context, context.getResources().getText(resId), duration);
	}

	public static void show(Context context, CharSequence text) {
		show(context, text, Toast.LENGTH_SHORT);
	}

	public static void show(Context context, int resId, Object... args) {
		show(context, String.format(context.getResources().getString(resId), args), Toast.LENGTH_SHORT);
	}

	public static void show(Context context, String format, Object... args) {
		show(context, String.format(format, args), Toast.LENGTH_SHORT);
	}

	public static void show(Context context, int resId, int duration, Object... args) {
		show(context, String.format(context.getResources().getString(resId), args), duration);
	}

	public static void show(Context context, String format, int duration, Object... args) {
		show(context, String.format(format, args), duration);
	}

	public static void clean(){
		if (toast!=null) {
			toast.cancel();
		}
		toast=null;
	}
}
